package org.hhchat.leetcode.hashtable;

import java.util.HashMap;

/**
 * Created this one by HMH on 2017/9/29.
 */
public class code219_easy {
    static class Solution {
        public boolean containsNearbyDuplicate(int[] nums, int k) {
            HashMap<Integer,Integer> hashmap = new HashMap<>();
            for(int i=0;i<nums.length;i++) {
                if (hashmap.get(nums[i]) != null) {
                    if (i - hashmap.get(nums[i]) <= k) {
                        return true;
                    }
                }
                hashmap.put(nums[i], i);
            }
            return false;
        }
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        System.out.println(solution.containsNearbyDuplicate(new int[]{-1,-1},1));
    }
}
